/*
 * @Descripttion:
 * @version:
 * @Author: 麦冬果果
 * @Date: 2021-07-14 13:19:02
 * @LastEditors: your name
 * @LastEditTime: 2021-09-03 10:54:57
 */
package boot

import (
	"fastapi/src/app/middlewares"

	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"github.com/gogf/gf/os/glog"
)

var Server = server{}

type server struct {
}

func (s1 *server) Run() {
	s := g.Server()
	// 添加URI与静态目录的映射
	s.AddStaticPath("/public", g.Cfg().GetString("server.ServerRoot"))
	//路由名称采用驼峰命名方式
	s.SetNameToUriType(ghttp.URI_TYPE_CAMEL)
	//https
	ishttps := g.Config().GetBool("https.httpsEnabled")
	if ishttps {
		httpsCert := g.Cfg().GetString("https.hTTPSCertPath")
		httpsKey := g.Cfg().GetString("https.hTTPSKeyPath")
		if httpsCert != "" && httpsKey != "" {
			s.EnableHTTPS(httpsCert, httpsKey)
		}
		if len(g.Cfg().GetString("https.httpsAddr")) > 0 {
			s.SetHTTPSPort(g.Cfg().GetInt("https.httpsAddr"))
		}
	}
	//s.EnableAdmin("/mdgg/debug")
	domain := g.Cfg().GetString("server.Domain")
	d := s.Domain(domain)
	d.Use(middlewares.CORS)

	glog.Debug("[server][服务开启]")
}
